/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-23 11:03:01
 * @LastEditTime: 2023-02-17 15:18:27
 */

import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import houseOpt from '@/biz/option/house.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
import channelTypeMgr from '@/biz/option/channelType'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
      title: '',
      minWidth: 50,
      type: 'checkbox',
      fixed: 'left'
    }, {
      title: '签约单编号',
      field: 'orderCode',
      minWidth: 170,
      slots: {
        default: (params, h) => {
          if (params.row.isBreakLowPrice == 1) {
            return table.cell.text(h, {
              value: params.row.orderCode + '(底)'
            })
          } else {
            return table.cell.text(h, {
              value: params.row.orderCode
            })
          }
        },
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '签约单编号',
            key: 'orderCode',
            placeholder: '请输入至少4位签约单编号',
            input: {},
            check: (val) => {
              if (val.orderCode.length < 4) {
                _this.$Message.warning('请输入至少4位签约单编号。')
              }
              return !(val.orderCode.length < 4)
            }
          })
        }
      }
    },
    {
      title: '签约房源',
      field: 'roomName',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, houseOpt.createRoom({
            key: 'roomId',
            title: '签约房源'
          }))
        }
      }
    },
    {
      title: '签约状态',
      field: 'status',
      minWidth: 150,
      cell: (item) => {
        return {
          text: {
            type: 'dict',
            key: 'status',
            color: item.status == 10102 ? '#D9001B' : '#515a6e'
          }
        }
      },
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '签约状态',
            key: 'statusList',
            placeholder: '请选择签约状态',
            select: {
              multiple: true,
              options: dt.dictInfo().status.filter(item => {
                return item.key ==
                  10104 || item.key == 10109 || item.key == 10108
              })
            },
          })
        }
      }
    },
    {
      field: 'customerName',
      minWidth: 150,
      title: '客户姓名',
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '客户姓名',
            key: 'customerName',
            placeholder: '请输入客户姓名',
            input: {},
          })
        }
      }
    },
    {
      title: '客户手机号',
      field: 'customerPhone',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '客户手机号',
            key: 'customerPhone',
            placeholder: '请输入至少4位客户手机号',
            input: {},
            check: (val) => {
              if (val.customerPhone.length < 4) {
                _this.$Message.warning('请输入至少4位客户手机号。')
              }
              return !(val.customerPhone.length < 4)
            }
          })
        }
      }
    },
    {
      minWidth: 130,
      field: 'counselorName',
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, nameOpt.createPushPeople({
            key: 'counselorId',
            title: '归属顾问',
            to: (info) => {
              return {
                counselorId: info.userId
              }
            }
          }))
        }
      }
    },
    {
      title: '所属产品',
      field: 'productName',
      minWidth: 180,
      cell: {
        text: {
          lineClamp: 2,
          webkitBoxOrient: 'vertical',
          display: '-webkit-box',
          whiteSpace: 'inherit'
        }
      }
    },
    {
      title: '面积（㎡）',
      field: 'area',
      minWidth: 150,
    },
    {
      title: '认购总价（元）',
      field: 'sumPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约单价（元）',
      field: 'unitPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约总价（元）',
      field: 'totalPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '累计到账房款（元）',
      field: 'accumulateBill',
      minWidth: 180,
      cell: {
        text: {
          type: 'number'
        }
      }
    }, {
      title: '剩余未到账房款（元）',
      field: 'residueBill',
      minWidth: 180,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '全款到账日期',
      field: 'accountDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, dateOpt.range({
            title: '全款到账日期',
            startKey: 'accountDateStart',
            endKey: 'accountDateEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.accountDateStart, val
                  .accountDateEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('全款到账日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.accountDateStart, val
                .accountDateEnd).Y >= 2)
            }
          }))
        }
      }
    },
    {
      title: '渠道名称',
      field: 'channelName',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, houseOpt.createChannel({
            key: 'channelId',
            title: '渠道名称'
          }))
        }
      }
    },
    {
      title: '合作类型',
      field: 'channelType',
      minWidth: 120,
      cell: {
        text: {
          type: 'dict',
          key: 'cooperationTypeFinal'
        }
      },
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h,channelTypeMgr.create({
            key: 'cooperationType',
          }))
        }
      }
    },
    {
      field: 'channelCostValue',
      title: '渠道费用(元)',
      width: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约日期',
      field: 'subscriptionDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, dateOpt.range({
            title: '签约日期',
            startKey: 'subscriptionStartDate',
            endKey: 'subscriptionEndDate',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.subscriptionStartDate, val
                  .subscriptionEndDate).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('签约日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.subscriptionStartDate, val
                .subscriptionEndDate).Y >= 2)
            }
          }))
        }
      }
    },
    {
      title: '签约人',
      field: 'contractorName',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, nameOpt.createContractor({
            key: 'contractorId',
            title: '签约人'
          }))
        }
      }
    }]
  }
}

export default Column